"""
查询原始语言
"""

from sqlalchemy import create_engine
from sqlalchemy import text
engine = create_engine('mysql://stock:stockjj@127.0.0.1/test?charset=utf8', echo=True)

def ex1():
    sql = """SELECT id, name, fullname
            FROM users
            WHERE name = %s
    """
    conn = engine.connect()
    result = conn.execute(sql, ('jack',))
    print(type(result))
    for row in result:
        print(row)
    result.close()
    conn.close()

def ex2():
    sql = """SELECT id, name, fullname
            FROM users
            WHERE name = :name
    """
    conn = engine.connect()
    result = conn.execute(text('SELECT * from users where name = :name'), {'name':'jack'})
    print(type(result))
    for row in result:
        print(row)
    result.close()
    conn.close()

def ex3():

    conn = engine.connect()
    result = conn.execute(text('Update users set fullname = :fullname where name = :name'), {'name':'jack', 'fullname':'坐过'})
    print(type(result))
    conn.close()

if __name__ == '__main__':
    ex3()